package inventoryservicelogic

import (
	"context"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type InventoryAssetReturnDetailEditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewInventoryAssetReturnDetailEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InventoryAssetReturnDetailEditLogic {
	return &InventoryAssetReturnDetailEditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// InventoryAssetReturnDetailEdit 更新资产退库明细表项
func (l *InventoryAssetReturnDetailEditLogic) InventoryAssetReturnDetailEdit(in *property_service.InventoryAssetReturnDetail) (*property_service.Response, error) {
	// 获取资产退库明细表模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).InventoryAssetReturnDetail
	// 构建查询条件：根据ID查询
	do := m.WithContext(l.ctx).Where(m.ID.Eq(in.ID))
	// 执行更新操作，仅更新指定字段，不包含ID、TenantID、CreatedAt、UpdatedAt
	if _, err := do.UpdateColumns(&model.InventoryAssetReturnDetail{
		ReturnID:          in.ReturnID,          // 退库单ID
		AssetID:           in.AssetID,           // 资产ID
		AssetCode:         in.AssetCode,         // 资产编号
		AssetName:         in.AssetName,         // 资产名称
		Category:          in.Category,          // 分类
		CategoryID:        in.CategoryID,        // 分类ID
		SpecModel:         in.SpecModel,         // 规格型号
		Brand:             in.Brand,             // 品牌
		BrandID:           in.BrandID,           // 品牌ID
		Origin:            in.Origin,            // 产地
		OriginID:          in.OriginID,          // 产地ID
		Unit:              in.Unit,              // 单位
		UnitID:            in.UnitID,            // 单位ID
		UnitPrice:         in.UnitPrice,         // 单价
		UnitPriceID:       in.UnitPriceID,       // 单价ID
		Quantity:          in.Quantity,          // 数量
		StorageLocation:   in.StorageLocation,   // 存放地点
		StorageLocationID: in.StorageLocationID, // 存放地点ID
		Manufacturer:      in.Manufacturer,      // 生产商
		ManufacturerID:    in.ManufacturerID,    // 生产商ID
		UpdatedAtuser:     in.UpdatedAtuser,     // 更新人
	}); err != nil {
		// 如果更新失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 更新成功，返回成功响应
	return result.Suc().EditEd()
}
